// pages/my/my-brief .js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  copy(e) {
    var text = e.currentTarget.dataset.message;
    wx.setClipboardData({
      data: text,
      success: (res) => {
        wx.showToast({
          title: '复制成功',
        });
      },
    })
  },

  bindPhone(e) {
    wx.makePhoneCall({
      phoneNumber: this.data.about.phone + '',
    })
  },

  bindAddress(e) {
    var that = this;
    wx.openLocation({
      latitude: parseFloat(that.data.about.lat),
      longitude: parseFloat(that.data.about.lng),
      address: that.data.about.address,
    })
  },

  goBlank(e) {
    wx.navigateBack({
      delta: 1,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this
    let system = app.globalData.system;
    that.setData({
      system,
    })
    wx.showLoading({
      title: '玩命加载中',
      mask: true,
    })
    wx.request({
      url: app.globalData.url + 'Aboutme',
      method: 'POST',
      data: {
        uid: app.globalData.uid,
        type: that.data.navNum,
      },
      success: function (res) {
        if (res.data.info) {
          that.setData({
            about: res.data.info.about,
          })
        }
        if (res.data.info.about.content) {
          var content = res.data.info.about.content
          content = content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')
          that.setData({
            content,
          })
        }
        wx.hideLoading()
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 监听页面滚动
  onPageScroll: function (res) {
    const that = this;
    if (res.scrollTop < 200) {
      this.setData({
        scrollTop: 1
      })
    } else if (res.scrollTop >= 210) {
      this.setData({
        scrollTop: 2
      })
    }
    console.log(res.scrollTop)
  },
})